package com.cs2340.taskplusplus;

/**
 * This class represents a user's account, stores account information,
 * and retrieves/saves that information to the database.
 * 
 * @author GRILLENBANNER
 *
 */
public class Account 
{
	public static String username;
	private String password, realname, email;
	private TaskList masterList;
	
	/**
	 * Creates a new account and saves it to the database
	 * @param username
	 * @param password
	 * @param realname
	 * @param email
	 */
	public Account(String username, String password, String realname, String email)
	{
		this.setPassword(password);
		Account.username = username;
		this.setRealname(realname);
		this.setEmail(email);
		AccountDatabase.createAccount(this);
		this.masterList = new TaskList(null, "MasterList", null, null, null, null);
	}
	
	/**
	 * Constructs an existing account from the database, using the account's name as an identifier.
	 * @param username
	 */
	public Account(String username)
	{
		Account.username = username;
		this.masterList = new TaskList(username+"_MasterList");
		AccountDatabase.fillInfo(this);
	}
		
	public void setMasterList(TaskList list)
	{
		this.masterList = list;
	}

	public TaskList getMasterList()
	{
		return masterList;		
	}
	
	public void deleteAccount(String name)
	{
		AccountDatabase.deleteAccount(name);
		new TaskList(name+"_MasterList").delete();
	}
	
	/**
	 * Returns true if the parameter matches the password
	 * @param pass
	 * @return
	 */
	public boolean checkPass(String pass){
		return password.equals(pass);
	}
	
	/**
	 * Returns true if the parameter matches the username
	 * @param name
	 * @return
	 */
	public boolean checkUsername(String name){
		return username.equals(name);
	}

	/**
	 * Get username
	 * @return
	 */
	public String getUsername() {
		return username;
	}

	/**
	 * set username
	 * @param username
	 */
	public static void setUsername(String username) {
		Account.username = username;
	}

	/**
	 * gets password
	 * @return
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * sets password
	 * @param password
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * gets the user's real name
	 * @return
	 */
	public String getRealname() {
		return realname;
	}

	/**
	 * set's the user's real name
	 * @param realname
	 */
	public void setRealname(String realname) {
		this.realname = realname;
	}

	/**
	 * get the user's email address
	 * @return
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * sets the user's email address
	 * @param email
	 */
	public void setEmail(String email) {
		this.email = email;
	}
	
}
